﻿@model IEnumerable<ScrumProject.Models.Story>
           
@{
    ViewBag.Title = "SprintBacklog";
    Layout = "~/Views/Shared/_Layout.cshtml";
    ScrumProject.Models.UserRepository usr = new ScrumProject.Models.UserRepository();
}

<h2>Sprint Backlog</h2>
<center>
@if (Model == null)
{    
    <div style="font-size : x-large; color : InfoText">No sprint running!</div> 
}
else if(Model.FirstOrDefault() == null){
    <div style="font-size : x-large; color : InfoText">No stories in current sprint!</div> 
}
else
{
    ScrumProject.Models.UserRepository ur = new ScrumProject.Models.UserRepository();
    ScrumProject.Models.StoryRepository sr = new ScrumProject.Models.StoryRepository();
    <br />
    <div id="stories" style="width:700px;">
   
    
    @foreach (var item in Model)
    {
        if (item.Status.CompareTo("active    ") != 0) { continue; }
        string[] testi = item.Tests.Split('\n');
        string hash = "# ";
        string u = "";
        <table class='table table-condensed'  style="border: 1px solid #CFCACC;">
            <thead>
                <tr>
                    <th style="text-align: left; background-image: -moz-linear-gradient(center top , rgb(203, 203, 203) 0%, rgb(234, 234, 234) 100%);">
                        <h5><b>@item.Name</b></h5>
                        Priority: @item.Priority&nbsp;|&nbsp;Business value: @item.BusinessValue&nbsp;|&nbsp;Actions: @Html.ActionLink("Notes", "Notes", "Story", new { id = item.Id }, null),@Html.ActionLink("Tasks", "Index", "Task", new { storyId = item.Id }, null)
                    </th>
                    <th style="text-align: right; background-image: -moz-linear-gradient(center top , rgb(203, 203, 203) 0%, rgb(234, 234, 234) 100%);">
                        Estimate: @item.TimeComplexity pt | Work done: @((int)(sr.WorkDone(item.Id)!=null?sr.WorkDone(item.Id):0)) h
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr><td colspan="2">@item.Description</td></tr>
                <tr><td colspan="2" style="color:#0088cc;">
                        @foreach (string st in testi)
                        {
                            @hash  @st; <br />
                        }
                    </td></tr>
                <tr><td colspan="2">
                        <table class="table table-condensed">
                            <thead><tr>
                                    <th width="40%" style="text-align: left;">Tasks</th>
                                    <th width="25%" style="text-align: left;">Status/Action</th>
                                    <th width="25" style="text-align: left;">Member</th>
                                    <th width="10%" style="text-align: left;">Remaining</th>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach (var task in item.Tasks)
                            {
                                <tr><td style="text-align: left;">@task.Description</td>
                                    <td style="text-align: left;">
                                        @if ((task.Status.Equals(0) || task.Status.Equals(2)) && !task.WorkRemaining.Equals(0.0))
                                        {
                                            @Html.ActionLink("Accept task", "AcceptTask", "Task", new { taskId = task.Id }, null)
                                            //Write("Completed");
                                        }
                                        @if (task.Status.Equals(1))
                                        { 
                                            <label style="color:#EDA137">Assigned</label>
                                        }
                                        @if (task.Status.Equals(3))
                                        {
                                            <label style="color:#65C429">Completed</label>
                                        }
                                        @if (task.Status.Equals(4) || (task.Status.Equals(0) && (task.WorkRemaining.Equals(0.0))))
                                        { 
                                            <label style="color:#C4BBBE">Pending</label>
                                        } 
                                    </td>
                                    <td style="text-align: left;">
                                        @if (task.UserId == -1)
                                        {
                                            <label>Not selected</label>
                                        }
                                        else
                                        { 
                                            @ur.GetUser((int)task.UserId).Username    
                                        }
                                    </td>
                                    <td style="text-align: left;">@task.WorkRemaining</td>
                                </tr>
                            }
                            </tbody>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    }
    </div>        
}
    </center>
    <br/>
